import '../../helper/dioHelper.dart';

class LayerOption {
  int Id;
  int TypeId;
  String LayerName;
  String Points;
  double LineWidth;
  int IconCode;
  int ColorA;
  int ColorR;
  int ColorG;
  int ColorB;
  String Remarks;

  LayerOption(
      this.Id,
      this.TypeId,
      this.LayerName,
      this.Points,
      this.LineWidth,
      this.IconCode,
      this.ColorA,
      this.ColorR,
      this.ColorG,
      this.ColorB,
      this.Remarks);
  LayerOption.fromJson(Map<String, dynamic> json)
      : Id = json["Id"],
        TypeId = json["TypeId"],
        LayerName = json["LayerName"],
        Points = json["Points"],
        LineWidth = json["LineWidth"],
        IconCode = json["IconCode"],
        ColorA = json["ColorA"],
        ColorR = json["ColorR"],
        ColorG = json["ColorG"],
        ColorB = json["ColorB"],
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'Id': Id,
        'TypeId': TypeId,
        'LayerName': LayerName,
        'Points': Points,
        'LineWidth': LineWidth,
        'IconCode': IconCode,
        'ColorA': ColorA,
        'ColorR': ColorR,
        'ColorG': ColorG,
        'ColorB': ColorB,
        'Remarks': Remarks,
      };
  static Future<bool> Add(LayerOption x1) async {
    var response = await DioHelper.Post("/LayerOption/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(LayerOption x1) async {
    var response = await DioHelper.Post("/LayerOption/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(LayerOption x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/LayerOption/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<LayerOption?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/LayerOption/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new LayerOption.fromJson(response.data);
    return null;
  }

  static Future<List<LayerOption>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/LayerOption/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <LayerOption>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new LayerOption.fromJson(x));
      }
    }
    return list1;
  }
}
